package com.shop.user.atom.atomsvc.impl;

import com.shop.common.entity.user.UserBase;
import com.shop.common.model.ServiceBean;
import com.shop.common.tmpl.BaseService;
import com.shop.user.atom.atomsvc.IUserAtomSvc;
import com.shop.user.atom.atomsvc.IUserMappingAtomSvc;
import com.shop.user.conf.util.AccountType;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserMappingAtomSvc extends BaseService implements IUserMappingAtomSvc {
    //    @Autowired
//    TpUserMapper tpUserMapper;
    @Autowired
    IUserAtomSvc userService;

    @Override
    public Boolean openIdIsExists(String openId) {
//        TpUser tpUser=tpUserMapper.selectByPrimaryKey(openId);
        return null != null;
    }

    @Override
    public ServiceBean<String> saveTpUser(String openId, String nickName, String userLogo) {
        UserBase userBase = new UserBase();
        userBase.setAccount(openId);
        userBase.setPassword(DigestUtils.md5Hex(openId));
        userBase.setType(AccountType.QQ.getValue());
        userBase.setNickname(nickName);
        userBase.setUserlogo(userLogo);
        ServiceBean<Integer> result = userService.addUser(userBase);
        if (result.isSuccess()) {
//            TpUser tpUser=new TpUser();
//            tpUser.setOpenId(openId);
//            tpUser.setUserId(result.getData());
//            tpUser.setIsregist(-1);
//            tpUser.setStatus(UserState.Init.getValue());
//            tpUser.setType(TpType.QQ.getValue());
//            tpUser.setCreateTime(DateUtil.newNowDate());
//            tpUserMapper.insertSelective(tpUser);
        }
        return null;
    }
}
